﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataTier;
using System.Data.SqlClient;
using System.Data.Common;

namespace DbLayer
{
    public class DbCity : DbObject, IDbCity
    {

        private static DbCity _instance = null;

        private DbCity()
        {
        }

        public static IDbCity Instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new DbCity();
                }
                return _instance;
            }
        }

        public string GetCity(int zipCode)
        {

            string query = BuildSelectStatement("ZipCodeCity", "zipCode = '" + zipCode.ToString() + "'");
            SqlDataReader reader = ExecuteQuery(query);
            string city = "";

            if (reader.Read())
            {
                city = BuildCity(reader);
            }

            reader.Close();

            return city;

        }

        private string BuildCity(SqlDataReader reader)
        {
            return reader["city"].ToString();
        }

    }
}
